package bluedot.spectrum.web.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import bluedot.spectrum.common.QueryObject;
import bluedot.spectrum.commons.entity.Dir;
import bluedot.spectrum.commons.entity.User;
import bluedot.spectrum.service.QueryService;
import bluedot.spectrum.web.core.ModelAndView;
import jxau.spectrum.frame.web.annotation.Autowired;
import jxau.spectrum.frame.web.annotation.Controller;
import jxau.spectrum.frame.web.annotation.RequestMapping;
import jxau.spectrum.frame.web.annotation.RequestParam;

/**
 * 文件夹业务
 * @author WFP
 * 2018年1月20日
 */
@Controller
@RequestMapping("/dir")
public class DirController extends BaseController {
	
	@Autowired
	private QueryService queryService;
	/**
	 * 查询（光谱/算法）文件夹---ajax请求
	 * WFP
	 * @param req
	 * @param resp
	 * @return
	 * 2018年1月21日
	 */
	@RequestMapping("/query/ajax")
	public Object queryDirAjax (HttpServletRequest req, HttpServletResponse resp){
	
        return renderSuccess();
	}
	/**
	 * 查询（光谱/算法）文件夹---普通请求
	 * WFP
	 * @param req
	 * @param resp
	 * @return
	 * 2018年1月21日
	 */
	@RequestMapping("/query")
	public Object queryDir (@RequestParam("dirtype")Integer dirtype,@RequestParam("start")Integer start,@RequestParam("end")Integer end,HttpServletRequest req, HttpServletResponse resp){
		//传给模板用来存储数据的model
        Map<String, Object> model = new HashMap<String, Object>();
        ModelAndView modelAndView = new ModelAndView();
        //往model中添加数据
        User user = (User)req.getSession().getAttribute("userSession");
        Map<String,Object> condition = new HashMap<>();
        condition.put("user_id", user.getUserId());
        condition.put("dir_type_id", dirtype);
        QueryObject queryParm = new QueryObject("dir", condition, start, end, null);
        List<HashMap<String,Object>> queryResult = queryService.query(queryParm);
        List<Dir> dirInfoList  = getBeanList(queryResult, Dir.class);
        modelAndView.addObject(dirInfoList);
        if(dirtype==1){
        	modelAndView.setViewName("/dir/algorithmdir");
        }else{
        	modelAndView.setViewName("/dir/spectrumdir");
        }
        return modelAndView;
	}
	
	/**
	 * 更新（光谱/算法）文件夹---ajax请求
	 * WFP
	 * @param req
	 * @param resp
	 * @return
	 * 2018年1月21日
	 */
	@RequestMapping("/update/ajax")
	public Object updateDirAjax (HttpServletRequest req, HttpServletResponse resp){

        return renderSuccess();
	}
	
	/**
	 * 删除（光谱/算法）文件夹---ajax请求
	 * WFP
	 * @param req
	 * @param resp
	 * @return
	 * 2018年1月21日
	 */
	@RequestMapping("/delete/ajax")
	public Object deleteDirAjax (HttpServletRequest req, HttpServletResponse resp){

        return renderSuccess();
	}
	
}
